package com.dnjn.happiness.emo.api.factory;

import com.dnjn.happiness.common.core.domain.R;
import com.dnjn.happiness.common.core.model.HxBeanSeed;
import com.dnjn.happiness.emo.api.RemoteEmoUserService;
import com.dnjn.happiness.emo.api.model.EmoUserBean;
import com.dnjn.happiness.emo.api.model.EmoUserVO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public class RemoteEmoUserFallbackFactory implements FallbackFactory<RemoteEmoUserService> {

    private static final Logger log = LoggerFactory.getLogger(RemoteEmoUserFallbackFactory.class);

    @Override
    public RemoteEmoUserService create(Throwable throwable) {
        log.error("调用emoUser服务失败：" + throwable.getMessage());
        return new RemoteEmoUserService() {
            @Override
            public void updateHappinessScoreByUserId(Long userId, Integer hscore, String source) {
                log.error("updateHappinessScoreByUserId失败：{}" + throwable.getMessage());
            }

            @Override
            public R<Boolean> updateWorkDate(Long userId, String source) {
                return R.fail("更新WorkDate失败：{}" + throwable.getMessage());
            }

            @Override
            public R<List<EmoUserBean>> selectByLimit(int index, int num, String source) {
                return R.fail("查询用户列表失败：{}" + throwable.getMessage());
            }

            @Override
            public R<Long> getCount(String source) {
                return R.fail("查询用户数量失败：{}" + throwable.getMessage());
            }

            @Override
            public R<EmoUserVO> saveEmoUser(HxBeanSeed beanSeed, String source) {
                return R.fail("保存emoUser失败：{}" + throwable.getMessage());
            }

            @Override
            public void delEmoUser(HxBeanSeed beanSeed, String source) {
                log.error("删除emoUser失败：{}" + throwable);
            }

            @Override
            public R<Boolean> updateHBean(HxBeanSeed beanSeed, String source) {
                return R.fail("更新快乐豆失败: {}" + throwable.getMessage());
            }

            @Override
            public R<EmoUserVO> getInfoByUserId(Long userId, String source) {
                return R.fail("获取emoUser失败: {}" + throwable.getMessage());
            }

            @Override
            public R<Boolean> updateHappinessScores(Long userId, Integer happinessScores, String source) {
               return R.fail("更新快乐值失败：{}" + throwable.getMessage());
            }

            @Override
            public R<EmoUserVO> saveEmoUserById(Long userId, String source) {
                return R.fail("保存emoUser失败: {}" + throwable.getMessage());
            }

            @Override
            public R<List<EmoUserVO>> selectUserList(String source) {
                return R.fail("查询emoUser失败: {}" + throwable.getMessage());
            }

            @Override
            public void emptytheHappyBeansToday(String source) {
                log.error("清空今日快乐豆失败：{}" + throwable.getMessage());
            }
        };
    }
}
